﻿using System;
using Styx.WoWInternals;

// ReSharper disable CheckNamespace
namespace F2FTraderq
// ReSharper restore CheckNamespace
{
    public partial class Main
    {

        public void PostCustomMessage()
        {
            Stopwatch.Start();
            if (Stopwatch.IsRunning)
            {
                if (MIRsettings.Instance.PostMessageTimer != 0 &&
                    Stopwatch.IsRunning &&
                    Stopwatch.Elapsed.Minutes > MIRsettings.Instance.PostMessageTimer +
                    TimeSpanUtil.ConvertMillisecondsToMinutes(new Random().Next(5000, 25000)))
                {
                    Log("Posting to Trade... " + DateTime.Now.ToLocalTime());
                    Lua.DoString("SendChatMessage(\"" + MIRsettings.Instance.SendMessage + "\",\"channel\",nil,2)");
                    Stopwatch.Reset();
                    Stopwatch.Stop();
                }
            }
        }

        public void PostDefaultMessage()
        {
            Stopwatch.Start();
            if (Stopwatch.IsRunning)
            {
                if (MIRsettings.Instance.PostMessageTimer != 0 &&
                    Stopwatch.IsRunning &&
                    Stopwatch.Elapsed.Minutes > MIRsettings.Instance.PostMessageTimer +
                    TimeSpanUtil.ConvertMillisecondsToMinutes(new Random().Next(5000, 25000)))

                    Lua.DoString("SendChatMessage(\"WTS \"..select(2,GetItemInfo(" +
                                 RemoveDigits(MIRsettings.Instance.SelectedItem) + "))..\"" + " " +
                                 MIRsettings.Instance.SendMessage + "\",\"channel\",nil,2)");
                Stopwatch.Reset();
                Stopwatch.Stop();
            }
        }

        public void PostManualCustomMessage()
        {
            Log("[Manual] Posting to Trade... " + DateTime.Now.ToLocalTime());
            Lua.DoString("SendChatMessage(\"" + MIRsettings.Instance.SendMessage + "\",\"channel\",nil,2)");
        }

        public void PostManualDefaultMessage()
        {
            Log("[Manual] Posting to Trade... " + DateTime.Now.ToLocalTime());
            Lua.DoString("SendChatMessage(\"WTS \"..select(2,GetItemInfo(" +
                         new Main().RemoveDigits(MIRsettings.Instance.SelectedItem) + "))..\"" + " " +
                         MIRsettings.Instance.SendMessage + "\",\"channel\",nil,2)");
        }
    }
}